package com.czy.owner.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.FindActivityModel;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/5/15 0015.
 */

public class FindActivityRecommondAdapter extends RecyclerArrayAdapter<FindActivityModel> {
    private Context context;

    public FindActivityRecommondAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ActivityRecommondViewHolder(parent,context);
    }

    class ActivityRecommondViewHolder extends BaseViewHolder<FindActivityModel> {

        private ImageView imgItemFind;
        private TextView tvItemFindName;
        private TextView tvItemFindTime;

        public ActivityRecommondViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_find_activity);
            imgItemFind = $(R.id.img_item_find);
            tvItemFindName = $(R.id.tv_item_find_name);
            tvItemFindTime = $(R.id.tv_item_find_time);
        }

        @Override
        public void setData(FindActivityModel data) {
            super.setData(data);
            tvItemFindName.setText(data.getTitle());
//            if(data.getStopTime()-System.currentTimeMillis()>=0){
//                if(!TextUtils.isEmpty(TimeUtils.getFitTimeSpan(data.getStopTime(),System.currentTimeMillis(),2))){
//                    tvItemFindTime.setText("过时不候-"+TimeUtils.getFitTimeSpan(data.getStopTime(),System.currentTimeMillis(),2));
//                }else {
//                    tvItemFindTime.setText("过时不候-"+TimeUtils.getFitTimeSpan(data.getStopTime(),System.currentTimeMillis(),3));
//                }
//
//            }else {
//                tvItemFindTime.setText("已过期");
//            }

                GlideUtils.loadImage(context, data.getLogo(), imgItemFind, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                    @Override
                    public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                    }

                    @Override
                    public void onLoadingError(String source, Exception e) {

                    }
                },R.mipmap.default_banner,R.mipmap.default_banner);


        }
    }
}
